import 'dart:ui' as prefix0;

import 'package:baby/Entities/BroadCastAccount.dart';
import 'package:baby/UI/Animations/MyPageRoute.dart';
import 'package:baby/UI/Pages/EdiucationPage/ArticleViewPage.dart';
import 'package:baby/UI/Widgets/ListDividerGenerator.dart';
import 'package:baby/UI/Widgets/UISpecifics/ArticleItem.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';

class BroadCastAccountHomePage extends StatefulWidget {
	final BroadCastAccount broadCastAccount;

	const BroadCastAccountHomePage({Key key, @required this.broadCastAccount}) : super(key: key);

	@override State<BroadCastAccountHomePage> createState() => _BroadCastAccountHomePageState();
}

class _BroadCastAccountHomePageState extends State<BroadCastAccountHomePage> with SingleTickerProviderStateMixin {
	TabController _controller;
	var categories = [
		"ھەممىسى",
		"ساغلاملىق",
		"بالىلار",
		"مۇزىكا",
		"رىسالە",
		"پىسخىكا",
		"بوۋاقلار",
	];

	@override initState() {
		_controller = TabController(length: categories.length, vsync: this);
		super.initState();
	}

	@override Widget build(BuildContext context) {
		return Directionality(
			textDirection: TextDirection.rtl,
			child: Scaffold(
				body: CustomScrollView(
						slivers: [
							SliverAppBar(
								expandedHeight: 250.0,
								flexibleSpace: FlexibleSpaceBar(
										background: Stack(
											children: <Widget>[
												CachedNetworkImage(imageUrl: widget.broadCastAccount.coverImage, fit: BoxFit.cover, width: double.infinity, height: double.infinity,),
												Align(
														alignment: Alignment.bottomCenter,
														child: Column(
															mainAxisSize: MainAxisSize.min,
															children: <Widget>[
																Padding(
																	padding: EdgeInsets.symmetric(horizontal: 10.0),
																	child: Row(
																		children: <Widget>[
																			Hero(
																				tag: "BroadCaster:${widget.broadCastAccount.name}",
																				child: CircleAvatar(
																					radius: 40.0,
																					backgroundColor: Theme.of(context).primaryColor,
																					backgroundImage: CachedNetworkImageProvider(widget.broadCastAccount.avatarUrl),
																				),
																			),
																			SizedBox(width: 10.0,),
																			Expanded(
																				child: Column(
																					crossAxisAlignment: CrossAxisAlignment.start,
																					mainAxisSize: MainAxisSize.min,
																					children: <Widget>[
																						Text(widget.broadCastAccount.name, style: TextStyle(fontSize: 20.0), maxLines: 1, overflow: TextOverflow.ellipsis,),
																						Text(widget.broadCastAccount.comment),
																					],
																				),
																			),
																		],
																	),
																),
																Container(
																	padding: EdgeInsets.symmetric(vertical: 12.0),
																	color: Color(0x60000000),
																	child: Row(
																		mainAxisAlignment: MainAxisAlignment.spaceAround,
																		children: ListDividerGenerator([
																			Text("دەلىللەنگەن", style: TextStyle(color: Colors.white)),
																			Text("دەلىللەنگەن", style: TextStyle(color: Colors.white)),
																			Text("دەلىللەنگەن", style: TextStyle(color: Colors.white)),
																			Text("دەلىللەنگەن", style: TextStyle(color: Colors.white)),
																		], Container(color: Colors.white, width: 0.2, height: 25,)).items,
																	),
																),
															],
														)
												)
											],
										)
								),
							),
							SliverList(
								delegate: SliverChildListDelegate([
									TabBar(
										indicatorColor: Theme.of(context).primaryColor,
										unselectedLabelColor: Colors.black45,
										labelColor: Theme.of(context).primaryColor,
										isScrollable: true,
										tabs: categories.map((category) => Tab(child: Text(category),)).toList(),
										controller: _controller,
									),
									Padding(
										padding: EdgeInsets.all(10.0),
										child: Column(
											children: ListDividerGenerator(widget.broadCastAccount.articles.map((article) => Builder(
														builder: (context) =>
																ArticleItem(
																	article: article,
																	onTap: () {
																		Navigator.of(context).push(MyPageRoute(builder: (context) => ArticleViewPage(
																			article: article,
																		)));
																	},
																),
													)).toList(), Divider()).items,
										),
									),
								]),
							)
						]
				),
			),
		);
	}
}

